<?php
namespace app\index\controller;
use think\Controller;
use think\Loader;
use rsa\Rsa;
use think\Exception;
use think\Cache;
use think\Db;
use com\Des;
class Index extends Controller
{
    const DOMAIN = 'http://member.stholding.cn';
    //流水号查订单
    public function consume(){
        $post_data['pos_order'] ='34212042120';
        $post_data['vip_no'] ='20000003';
        $post_data['stid'] ='rysy';
        $post_data['order_detail'] ='{"orderId":"20180601170530"}';
        $post_data['score'] ='100';
        $json_data = json_encode($post_data);
        $rsa =new Rsa();
        $token           = time();
        // 公钥加密
        $data=array("data"=>$rsa->pubEncrypt($json_data),"token"=>$token);//post参数
        $url= self::DOMAIN."/api/ry/Order/consume";
        $result = http_post($url, $data);
        $resultArr = json_decode($result,true);
        //公钥解密
        echo $result;
    }

    
    public function exportToExcel()
    {//tp导入到excel
    $member = model('member');
    $member = $member->field( 'id,mobile,real_name')->select();
    $str = "编号,手机,真实姓名";
    $exl11 = explode(',',$str);
    foreach ($member as $k => $v){
         
        $exl[$k] = $v->getData();
    
    }
    exportToExcel('sfq.csv',$exl11,$exl);
    /*
    foreach ($pp as $kkk => $vvv) {
        $rs[$kkk] = $res->field('l.id lid,l.user_id,l.shop_id,l.code_num,l.code_src,l.winning_time,l.exchange_time,l.status,l.item_id iid,i.title,i.money,s.coder,u.nickname,u.head,s.manager,s.phone')->alias('l')->where($where)->join('sd_item i ON i.id=l.item_id')->join('left join  sd_shop s ON s.id=l.shop_id')->join('sd_user u ON u.id=l.user_id')->page($vvv.', 10000')->select();
    
        $str[$kkk] = "用户昵称,兑奖门店号,核销员,核销员手机号,中奖时间,兑换时间,奖项名称,中奖金额,中奖码,兑换状态";
    
        $exl11[$kkk] = explode(',',$str[$kkk]);
        foreach ($rs[$kkk] as $k => $v){
    
            if (!$v['nickname']) $v['nickname']           = '暂无数据';
            if (!$v['coder']) $v['coder']                 = '暂无数据';
            if (!$v['manager']) $v['manager']             = '暂无数据';
            if (!$v['phone']) $v['phone']                 = '暂无数据';
            if (!$v['winning_time']) $v['winning_time']   = '暂无数据';
            if (!$v['exchange_time']) $v['exchange_time'] = '暂无数据';
            if (!$v['title']) $v['title']                 = '暂无数据';
            if (!$v['money']) $v['money']                 = '暂无数据';
             
            $exl[$kkk][] = array(
                $v['nickname'],$v['coder'],$v['manager'],$v['phone'],$v['winning_time'],$v['exchange_time'],$v['title'],$v['money'],$ssssd[$v['status']]
            );
    
        }
    
        exportToExcel('兑奖记录_'.time().$vvv.'.csv',$exl11[$kkk],$exl[$kkk]);
    }*/
    exit();
    }
    public function ctime(){
        //echo strtotime("20180726 23:59:01"), "\n";
        echo strtotime("20180731 23:59:59"), "\n";
    }
    public function test_chr(){
        $code = chr(mt_rand(0xB0, 0xF7)) . chr(mt_rand(0xA1, 0xFE)) .       chr(mt_rand(0xB0, 0xF7)) . chr(mt_rand(0xA1, 0xFE)) . chr(mt_rand(0xB0, 0xF7)) . chr(mt_rand(0xA1, 0xFE));
        //var_dump($code) ;
        echo hexdec(0xB0);
    }
    public function insert(){
        
        $deposit['vip_no']      = 91000265;
        $deposit['money']       = 100;
        $deposit['pay_type']    = 1;
        $deposit['create_time'] = time();
        $deposit['deposit_operator'] ='song';
        Db::name('deposit') ->insert($deposit);
        $id = Db::name('deposit') ->getLastInsID();
        echo $id;
    }
    public function deposit(){
        $post_data['vip_no'] ='91000054';
        $post_data['money'] ='200';
        $post_data['stid'] ='rysy';
        $post_data['pay_type'] ='3';
        $json_data = json_encode($post_data);
        $rsa =new Rsa();
        $token           = time();
        // 公钥加密
        $data=array("data"=>$rsa->pubEncrypt($json_data),"token"=>$token);//post参数
        $url= self::DOMAIN."/api/ry/Order/deposit";
        $result = http_post($url, $data);
        $resultArr = json_decode($result,true);
        //公钥解密
        echo $result;
    }
    
    public function myQrcode(){
        $post_data['mobile'] ='18840877619';
        $post_data['openid'] ='13272703027';
        $json_data = json_encode($post_data);
        $rsa =new Rsa();
        $token           = time();
        // 公钥加密
        $data=array("data"=>$rsa->pubEncrypt($json_data),"token"=>$token);//post参数
        $url=self::DOMAIN."/api/xcx/Member/myQrcode";
        $result = http_post($url, $data);
        $resultArr = json_decode($result,true);
        //公钥解密
        echo $result;
    }
    public function resetPassword(){
        $post_data['mobile'] ='18223282442';
        $post_data['openid'] ='13272703027';
        $post_data['psw_type'] ='pay_password';
        $post_data['id_card'] ='52212819651109563X';
        $json_data = json_encode($post_data);
        $rsa =new Rsa();
        $token           = time();
        // 公钥加密
        $data=array("data"=>$rsa->pubEncrypt($json_data),"token"=>$token);//post参数
        $url=self::DOMAIN."/api/xcx/Member/resetPassword";
        $result = http_post($url, $data);
        $resultArr = json_decode($result,true);
        //公钥解密
        echo $result;
    }
    public function personalUpdate(){
        $post_data['mobile'] ='18840877619';
        $post_data['openid'] ='13272703027';
        $json_data = json_encode($post_data);
        $rsa =new Rsa();
        $token           = time();
        // 公钥加密
        $data=array("data"=>$rsa->pubEncrypt($json_data),"token"=>$token);//post参数
        $url=self::DOMAIN."/api/xcx/Member/myQrcode";
        $result = http_post($url, $data);
        $resultArr = json_decode($result,true);
        //公钥解密
        echo $result;
    }
    public function getUrlByFile(){
        $content = file_get_contents(RUNTIME_PATH.'92.html');
        $counter = preg_match_all('/https:[\/]{2}[a-z]+[.]{1}[a-z\d\-]+[.]{1}[a-z\d]*[\/]*[A-Za-z\d-]*[\/]*[A-Za-z\d-]*/',$content,$urls);
        foreach( $urls[0] as $url )
        {
            echo $url.'<br/>';
        }
        echo $counter;
    }
    public function test_des(){
        if(1529569790+300<time()){
            echo 'ok';
        }else{
            echo 'no';
        }
        echo time();
            echo '<br/><br/><br/>';
    
            $des   = new Des();
        echo $des->decrypt('JuuMMJTXWWdJZREmLevktjHemQ+BjURGUYZB487D0Iz41qbRep2LbQ==');
    }
    

    public function orderDetail(){
        $post_data['order_id'] ='1529462763999';
        $post_data['openid'] ='13272703027';
        $json_data = json_encode($post_data);
        $rsa =new Rsa();
        $token           = time();
        // 公钥加密
        $data=array("data"=>$rsa->pubEncrypt($json_data),"token"=>$token);//post参数
        $url=self::DOMAIN."/api/xcx/Member/orderDetail";
        $result = http_post($url, $data);
        $resultArr = json_decode($result,true);
        //公钥解密
        echo $result;
    }
    public function orderList(){
        $post_data['vip_no'] ='20000339';
        $post_data['openid'] ='13272703027';
        $json_data = json_encode($post_data);
        $rsa =new Rsa();
        $token           = time();
        // 公钥加密
        $data=array("data"=>$rsa->pubEncrypt($json_data),"token"=>$token);//post参数
        $url=self::DOMAIN."/api/xcx/Member/orderList";
        $result = http_post($url, $data);
        $resultArr = json_decode($result,true);
        //公钥解密
        echo $result;
    }
    //流水号查订单
    public function statusQuery(){
        $post_data['order_id'] ='1528012024';
        $json_data = json_encode($post_data);
        $rsa =new Rsa();
        $token           = time();
        // 公钥加密
        $data=array("data"=>$rsa->pubEncrypt($json_data),"token"=>$token);//post参数
        $url= self::DOMAIN."/api/ry/Order/statusQuery";
        $result = http_post($url, $data);
        $resultArr = json_decode($result,true);
        //公钥解密
        echo $result;
    }
    public function getc(){
        $id    = Db::name('member')->where('mobile', '13808336662')->column('id');
        var_dump($id);exit;
        echo strlen('<textarea id="copytext" class="magnetlink form-control" rows="3" onclick="$(this).select();" readonly="readonly">');
        exit;
        $orderId         = time();
        //加三位随机码
        $code = rand(100, 999);
        $orderId =$orderId .$code;
        echo  $orderId;
            
    }
    //流水号查订单
    public function gatewayStatusQuery(){
        $post_data['order_id'] ='1528178114';
        $json_data = json_encode($post_data);
        $rsa =new Rsa();
        $token           = time();
        // 公钥加密
        $data=array("data"=>$rsa->pubEncrypt($json_data),"token"=>$token);//post参数
        $url= self::DOMAIN."/api/ry/Gateway/statusQuery";
        $result = http_post($url, $data);
        $resultArr = json_decode($result,true);
        //公钥解密
        echo $result;
    }
    //小程序确认
    public function verifyConsume(){
        $post_data['order_id'] ='1528965053';
        $post_data['pay_type'] = 1;
        $post_data['deviceId'] = 1000;
        $post_data['openid'] = 1;
        $post_data['act'] =  'ok';
        $json_data = json_encode($post_data);
        $rsa =new Rsa();
        $token           = time();
        // 公钥加密
        $data=array("data"=>$rsa->pubEncrypt($json_data),"token"=>$token);//post参数
        $url= self::DOMAIN."/api/xcx/Member/verifyConsume";
        $result = http_post($url, $data);
        $resultArr = json_decode($result,true);
        //公钥解密
        echo $result;
    }  
    //退货
    public function refund(){
        $post_data['order_id'] ='1528965053';
        $json_data = json_encode($post_data);
        $rsa =new Rsa();
        $token           = time();
        // 公钥加密
        $data=array("data"=>$rsa->pubEncrypt($json_data),"token"=>$token);//post参数
        $url= self::DOMAIN."/api/ry/Order/refund";
        $result = http_post($url, $data);
        $resultArr = json_decode($result,true);
        //公钥解密
        echo $result;
    }
    //收银员取消
    public function cancel(){
        $post_data['order_id'] ='1528959116';
        $post_data['vip_no'] ='20000002';
        $json_data = json_encode($post_data);
        $rsa =new Rsa();
        $token           = time();
        // 公钥加密
        $data=array("data"=>$rsa->pubEncrypt($json_data),"token"=>$token);//post参数
        $url= self::DOMAIN."/api/ry/Order/cancel";
        $result = http_post($url, $data);
        $resultArr = json_decode($result,true);
        //公钥解密
        echo $result;
    }
    public function payQrcode(){
        $post_data['openid'] =20000002;
        $json_data = json_encode($post_data);
        $rsa =new Rsa();
        $token           = time();
        // 公钥加密
        $data=array("data"=>$rsa->pubEncrypt($json_data),"token"=>$token);//post参数
        $url=self::DOMAIN."/api/xcx/Member/payQrcode";
        $result = http_post($url, $data);
        $resultArr = json_decode($result,true);
        //公钥解密
        echo $result;
    }

    public function getCache(){
        $mobileCode= Cache::get('mobileCode');
        var_dump($mobileCode);
    }
    //把链接保存到文件中
    public function sava()
    {
    
        for ($i=33;$i<35;$i++){
            set_time_limit(180);
            $content = file_get_contents("https://www.zhongziso.com/map/$i.xml");
            $counter = file_put_contents(APP_PATH.$i.'.html', $content);            
        }
        echo 'OK';
    
    }
    public function sendNotice(){
        $post_data['vip_no'] =20000002;
        $json_data = json_encode($post_data);

    
    }
    public function openid11(){
        $post_data['code'] ='023LBDnU0pqu8X1tMQoU0aeFnU0LBDns';
        $json_data = json_encode($post_data);
        $rsa =new Rsa();
        $token           = time();
        // 公钥加密
        $data=array("data"=>$rsa->pubEncrypt($json_data),"token"=>$token);//post参数
        $url=self::DOMAIN."/api/xcx/Member/openId";
        $result = http_post($url, $data);
        $resultArr = json_decode($result,true);
        //公钥解密
        echo $result;
    }
    public function httpsRead(){
        $post_data['vip_no'] =20000002;
        $json_data = json_encode($post_data);
        $rsa =new Rsa();        
        $token           = time();
        // 公钥加密
        $data=array("data"=>$rsa->pubEncrypt($json_data),"token"=>$token);//post参数
        $url="https://member.stholding.cn/api/ry/vip_info/read";
        $result = https_post($url,'post', $data);
        var_dump($data);
        //$resultArr = json_decode($result,true);
        //公钥解密
        //echo $result;
    }
    public function httpRead(){
        $post_data['vip_no'] =91010069;
        $json_data = json_encode($post_data);
        $rsa =new Rsa();        
        $token           = time();
        // 公钥加密
        $data=array("data"=>$rsa->pubEncrypt($json_data),"token"=>$token);//post参数
        $url="http://192.168.1.117/api/ry/vip_info/read";
        $result = http_post($url, $data);
        $resultArr = json_decode($result,true);
        //公钥解密
        echo $result;
    }
    public function t(){
        $rsa =new Rsa();
        //私钥解密
        try {
            echo $rsa->privDecrypt('a3DC9GnK8zWL41pz2yVwmluvyV+clR6ZbT91bfSaBt5HwLXapPvnJPs8PlWhjIf4CFfA1qzMvQjDhXq7yHLFXqvyGWZCbyD8CU1qE49LB4tCQPJWIOhKgNVBaDMXqLrA5ZMV1OMQg3Si6jd5KDCJyCc4R6Sf7OuNYOBDZgMifuBEmtD1v1TXqT7zOxUTujgj1tUZ0qS\/HW\/jI4cBjyp\/1Qd4p\/jIIZZm7T4KpSCyIcJk2d\/tsRZb16Eprg1xtVWqxQYKHIdXGoU0Qzl4dWrh4yqwK1qL6ZNTQ3Pf97nSa4jLs4CFXyaG+uWbzuzh8Ladv3lk4G5YTK\/mNxfX9Db7sI+jMg8Rky6aJQ6S0+flzYKRGMNQlVhewbYRmtlmvkv1NqzbCVCuBBE+S4LOPz7zepJyeJDw1ai\/I0Ig12Bz20XXV\/G0zSuEgPVNHBGEw8KGEF7D8Qn+yX9i6oVSgBx8BrAGQlPXrdwSaH56DOy+zXmNauPrZd74HCUVhRNDrGQfKOwu3AMXwW7BjjloOntnI6em5rlShJVfXLnX6BVKWBY+0s9S\/nefouzww1i8TILzZAitmFWS8RXSL0J0tBqJTuSvrdvmhdOCSLPZsFsfK8wF2RVLzjqeFjInawdpv5HIK6yOabo\/kiFoEwuTpg7irRTmMyhNTdc9G6f2CJt9vkc=');
        } catch (\Exception $e) {
            print $e->getMessage();
            exit();
        }        
    }
    public function decrypt_rsa()
    {
        $tel ='tNcgMp7PwkRSas9csxJDuRGyjAlwf5TPiVcrho0NWbNy1FvI4EykrXkPZf+sKAFbSHR9bj5WImYpOwl1HI+AIJD1sVBEdnE5v0OU9Cu/mxdgvwZzWMmtA7VwovQ655wVVvfRKaSBf/MHCnZMADqNQD0UwRSAELBjqdmdhu14KMg=';
/*         $encrypt= 'GZ9bgEq7dS/pfNf3uyZlYky+w160xsz1VsXTWppYNO/TYZjt7SrG0fH69CGX25Yx/m8Y+rKPYU5w2RT6cZ92YHn03v1i6LCI7LBmz32PLqAFC/G+SZsT4INgMYXp/szEaSC0exQyQYX4FUALly+bELP4IN0Ku1g3m815MoH/fw=';
        $rsa   = new Rsa();
        $decryptData = $rsa->privDecrypt($encrypt); */
        $rsa   = new Rsa();
        echo $rsa->privDecrypt($tel);
    }
    public function qr_code(){
        Loader::import('phpqrcode.phpqrcode');
         //二维码内容
        // $value = '有人说：爱一个人会卑微到尘埃里，然后开出花！'; //二维码内容   
        $value = '1';
        $errorCorrectionLevel = 'L';//容错级别   
        
        $matrixPointSize = 6;//生成图片大小   
        //生成二维码图片   
        \QRcode::png($value, 'qrcode.png', $errorCorrectionLevel, $matrixPointSize, 2); 
        $logo = 'logo.png';//准备好的logo图片   
        $QR = 'qrcode.png';//已经生成的原始二维码图   
            
        if ($logo !== FALSE) {   
            $QR = imagecreatefromstring(file_get_contents($QR));   
            $logo = imagecreatefromstring(file_get_contents(ROOT_PATH.'public'.DS.$logo));   
            $QR_width = imagesx($QR);//二维码图片宽度   
            $QR_height = imagesy($QR);//二维码图片高度   
            $logo_width = imagesx($logo);//logo图片宽度   
            $logo_height = imagesy($logo);//logo图片高度   
            $logo_qr_width = $QR_width / 5;   
            $scale = $logo_width/$logo_qr_width;   
            $logo_qr_height = $logo_height/$scale;   
            $from_width = ($QR_width - $logo_qr_width) / 2;   
            //重新组合图片并调整大小   
            imagecopyresampled($QR, $logo, $from_width, $from_width, 0, 0, $logo_qr_width,    
            $logo_qr_height, $logo_width, $logo_height);   
        }   
        //输出图片  
        
        imagepng($QR, APP_PATH.'../public/wx/helloweba.png');   
        echo '<img src=/wx/helloweba.png />'; 
    }
    public function cz(){
        $memberModel = new \app\common\model\Member();
        $member = $memberModel->getMemberByMobile('18223282442 ');
        $member['bank_name1'] = '中国人民银行';
        var_dump($member);
    }
    public function pt(){
        Loader::import('phpqrcode.phpqrcode');
        $data = 'J7LLZcXCRoSCr0lC5s2tgzK0ZlDaXfSQVcYeQ+3tt8GoxSO4eDCk+1NAvug3aau4TrBFvnjkRJ7lFwxEdjgaHIVVUmp0zpiPEEtqCYV8eOdGs0/9jQx3lbPxskLY79+o6t7es425B+znMqVaeCgUfIEkZTmE11Ll/1MUa9rUS0g=';
        $level = 'L';// 纠错级别：L、M、Q、H
        $size = 6;// 点的大小：1到10,用于手机端4就可以了
        $QRcode = new \QRcode();
        ob_start();
        $QRcode->png($data,false,$level,$size);
        $imageString = base64_encode(ob_get_contents());
        ob_end_clean();
        //return $imageString;
        echo '<img src="data:image/png;base64,'.$imageString.'" />';
    }
    public function img2(){
        echo '<img src="'.'" />';
    }
    public function setBase64(){
        //echo (fileToBase64(APP_PATH.'../public/wx/2.jpg')) ;
        //var_dump(fileToBase64(APP_PATH.'../public/wx/1.jpg')) ;
        //echo '<img src="' . fileToBase64(APP_PATH.'../public/wx/2.jpg') . '" />';
        //echo date('Y-m-d H:i:s',1526888024 );
        //echo time();
        $str = '';
        base64ToFile($str,APP_PATH.'../public/wx/3.jpg');
    }
    //根据电话匹配信息
    public function verifyPayPassword(){
        $post_data['mobile'] ='13272703027';
        $post_data['openid'] ='13983255120';
        $post_data['frequency'] ='2';
        $post_data['pay_password'] ='123456';
        $json_data = json_encode($post_data);
        $rsa =new Rsa();
        $token           = time();
        // 公钥加密
        $data=array("data"=>$rsa->pubEncrypt($json_data),"token"=>$token);//post参数
        $url=self::DOMAIN."/api/xcx/Member/verifyPayPassword";
        $result = http_post($url, $data);
        $resultArr = json_decode($result,true);
        //公钥解密
        echo $result;
    }
    public function xcxStatusQuery(){
        $post_data['phone'] ='13983255120';
        $json_data = json_encode($post_data);
        $rsa =new Rsa();
        $token           = time();
        // 公钥加密
        $data=array("data"=>$rsa->pubEncrypt($json_data),"token"=>$token);//post参数
        $url=self::DOMAIN."/api/xcx/Member/statusQuery";
        $result = http_post($url, $data);
        $resultArr = json_decode($result,true);
        //公钥解密
        echo $result;
    }
    
    public function barCode128(){
        $barcode = new \com\BarCode128('0301ZJ1204160018');
        //base64_encode($barcode->createBarCode());
        echo '<img src="'.$barcode->createBarCode().'" />';
        //'<img src="'.$barcode->createBarCode().'" />';
    }
    //条形码显示
    public function showImg(){
        //echo  '<br/><br/><br/><img src="/index/index/barCode128"  width="312" height="100"/>';
        echo  '<br/><br/><br/><img src="/index/index/bcode"/>';
    }
    public function bcode(){
        //Loader::import('BCode.phpqrcode');
        $content='1234567890128';
        // 引用barcode文件夹对应的类
        Loader::import('BCode.BCGFontFile',EXTEND_PATH);
        //Loader::import('BCode.BCGColor',EXTEND_PATH);
        Loader::import('BCode.BCGDrawing',EXTEND_PATH);
        // 条形码的编码格式
        Loader::import('BCode.BCGcode128',EXTEND_PATH,'.barcode.php');
        // $code = '';
        // 加载字体大小
        //$font = new BCGFontFile('./class/font/Arial.ttf', 18);
        //颜色条形码
        $color_black = new \BCGColor(0, 0, 0);
        $color_white = new \BCGColor(255, 255, 255);
        $drawException = null;
        try
        {
            $code = new \BCGcode128();
            $code->setScale(2);
            $code->setThickness(50); // 条形码的厚度
            $code->setForegroundColor($color_black); // 条形码颜色
            $code->setBackgroundColor($color_white); // 空白间隙颜色
            // $code->setFont($font); //
            $code->parse($content); // 条形码需要的数据内容
        }
        catch(\Exception $exception)
        {
            $drawException = $exception;
        }
        //根据以上条件绘制条形码
        $drawing = new \BCGDrawing('', $color_white);
        if($drawException) {
            $drawing->drawException($drawException);
        }else{
            $drawing->setBarcode($code);
            $drawing->draw();
        }
        // 生成PNG格式的图片
        header('Content-Type: image/png');
        // header('Content-Disposition:attachment; filename="barcode.png"'); //自动下载
        $drawing->finish(\BCGDrawing::IMG_FORMAT_PNG);
    }
    public function test_try(){
        /*
        if(preg_match('/^1[3456789]{1}\d{9}$/','13983255120')){
            echo 'ok';
        }else {
            echo 'error';
        }*/
        $psw = '###602ad3042fbeb80a3cc0abb58393ee3f';
        if(strpos($psw,'###') !== false){
            echo '找到数据';
        }else{
            echo '未找到了！';
        }
        /*
        try{
            echo 1/10;
        }catch (\Exception $e){
            echo $e->getMessage();
        }*/
        /*
        var_dump(Cache::get('mobileCode'));
        $state = '0O0K';
        if(stripos($state,'OK')>0){
            echo strpos($state,'OK');;
        }else {
            echo strpos($state,'OK');
        }*/
    }
    public function getMemberByMobile(){
        $post_data['mobile'] ='18840877619';
        $post_data['openid'] ='13272703027';
        $json_data = json_encode($post_data);
        $rsa =new Rsa();
        $token           = time();
        // 公钥加密
        $data=array("data"=>$rsa->pubEncrypt($json_data),"token"=>$token);//post参数
        $url=self::DOMAIN."/api/xcx/Member/getMemberByMobile";
        $result = http_post($url, $data);
        $resultArr = json_decode($result,true);
        //公钥解密
        echo $result;
    }
    
    
    public function getMember(){
        $post_data['mobile'] ='18223282442';
        $json_data = json_encode($post_data);
        $rsa =new \goldcardrsa\Rsa();
        $token           = time();
        // 公钥加密
        $data=array("data"=>$rsa->pubEncrypt($json_data),"token"=>$token);//post参数
        $url=self::DOMAIN."/api/goldcard/Member/getMember";
        $result = http_post($url, $data);
        $resultArr = json_decode($result,true);
        //公钥解密
        echo $result;
    }
    
    public function getAllMember(){
        $post_data['id'] ='1';
        $json_data = json_encode($post_data);
        $rsa =new \goldcardrsa\Rsa();
        $token           = time();
        // 公钥加密
        $data=array("data"=>$rsa->pubEncrypt($json_data),"token"=>$token);//post参数
        $url=self::DOMAIN."/api/goldcard/Member/getAllMember";
        $result = http_post($url, $data);
        $resultArr = json_decode($result,true);
        //公钥解密
        echo $result;
    }
    
    public function sendValidateionCode(){
        $post_data['mobile'] ='13272703027';
        $post_data['openid'] ='13272703027';
        $post_data['act'] = 'register';
        $json_data = json_encode($post_data);
        $rsa =new Rsa();
        $token           = time();
        // 公钥加密
        $data=array("data"=>$rsa->pubEncrypt($json_data),"token"=>$token);//post参数
        
        $url=self::DOMAIN."/api/xcx/Member/sendValidateionCode";
        $result = http_post($url, $data);
        $resultArr = json_decode($result,true);
        //公钥解密
        echo $result;
    }
    public function regPersonal(){
        $post_data['phone'] ='13983255120';
        $json_data = json_encode($post_data);
        $json_data = '{"stid":"xcx","openid":"oLNgT0VuvLMlM9oc7vN4VjYulY9I","real_name":"hc","mobile":"18840877619","mobileValidateCode":"34631","type":"1","id_card":"123","bank_card":"123","bank_name":"123","referee_mobile":"13983255120","token":"eyJhbGciOiJIUzI1NiJ9.eyJ1aWQiOiJTVEFTREZHSEpLTC4uLiIsInN1YiI6IntzdGlkOnhjeCxuYW1lOnhpYW9jaGVuZ3h1fSIsInVzZXJfbmFtZSI6ImFkbWluIiwibmlja19uYW1lIjoiU1RBUEkxMjMiLCJleHAiOjE1Mjg3OTEzMjMsImlhdCI6MTUyNzQ5NTMyMywianRpIjoic3RpZCJ9.dHqxrrGjQ2CRMhrU3gZBlVP0ejxgIBqQJWMKju53tUc","timeStamp":1527496375,"signature":"A20AC293E8C68645D2AF852369F740C4"}';
        $rsa =new Rsa();
        $token           = time();
        // 公钥加密
        $data=array("data"=>$rsa->pubEncrypt($json_data),"token"=>$token);//post参数
        $url=self::DOMAIN."/api/xcx/Member/personalRegiste";
        $result = http_post($url, $data);
        $resultArr = json_decode($result,true);
        //公钥解密
        echo $result;
    }
    public function checkValidateionCode(){
        $mobileCode['13272703027'] = '123456';
        //缓存验证码5分钟
        Cache::set('mobileCode',$mobileCode,300);
        $member = new \app\common\model\Member();
        $result = $member->checkValidateionCode('13272703027', '123456');
        if($result){
            echo 'true';
        }else {
            echo 'false';
        }
    }
    public function d(){
        $memberModel =new \app\common\model\Member();
        $member      =Db::name('member') ->field('*')->where('id', 18)->find();
        var_dump($member);
    }
    public function tt(){
        $openId = 'asdfasdf';
        if($openId){
            echo '有值';
        }else {
            echo '无值';
        }
    }
    public function slide(){
        $post_data['openid'] ='13983255120';
        $json_data = json_encode($post_data);
        $rsa =new Rsa();
        $token           = time();
        // 公钥加密
        $data=array("data"=>$rsa->pubEncrypt($json_data),"token"=>$token);//post参数
        $url=self::DOMAIN."/api/xcx/Member/slide";
        $result = http_post($url, $data);
        $resultArr = json_decode($result,true);
        //公钥解密
        echo $result;
    }
    public function s(){
        $member  = Db::name('member')->find(1);
        $f = 'real_name';
        if('熊友德'===$member[$f]){
            echo 'ok';
        }else {
            echo 'error';
        }
        
    }
    public function savaArticle(){
        //每次新增500篇
        //$urls = Db::name('gather_url')->where(['isdel'=>1]) ->limit(100)->select()->toArray();
        //foreach($urls as $url){
        $url['url'] ='https://www.zhongziso.com/info-AACFA3C39A7594935BE5AA30D7C94E2FB4D7CBBE';
        $id =time();
            $content = $this->https_post('https://www.zhongziso.com/info-AACFA3C39A7594935BE5AA30D7C94E2FB4D7CBBE');
            var_dump($content);
            preg_match('/<div class="text-left">(.*?)<\/div>/i',$content,$title);
            preg_match('/<textarea id="copytext" class="magnetlink form-control" rows="3" onclick="$(this).select();" readonly="readonly">(.*?)<\/textarea>/i',$content,$cili);
            preg_match('/<title>(.*?)<\/title>/i',$content,$title);
            preg_match('/<title>(.*?)<\/title>/i',$content,$title);
            preg_match('/<title>(.*?)<\/title>/i',$content,$title);
            $id = time();
            var_dump($title) ;
            exit;
            $portal         = [
                'id'   => $id,
                'parent_id'   => 0,
                'post_type'   => 1,
                'shot_time'   => '未知',
                'types'   => '电影',
                'language' => '英语',
                'post_format'   => 1,
                'user_id'   => 1,
                'post_status'   => 1,
                'comment_status'   => 1,
                'source_url'   => $url['url'],
                'file_size'   => '1G',
                'file_list'   => 1,
                'cili'   => 1,
                'xunlei'   => 1,
                'xiazai'   => 1,
                'is_top'   => 0,
                'post_hits'   => 12,
                'comment_count'   => 0,
                'update_time'   => time(),
                'published_time'   => time(),
                'delete_time'   => time(),
                'post_title'   => $title,
                'post_keywords'   => 0,
                'post_excerpt'   => 0,
                'post_content'   => 0,
                'more'   => '{"thumbnail":"","template":""}',
                'create_time' => time(),
                	
            ];
            var_dump($portal);exit;
            Db::name('portal_post')->insert($portal);
            	
            $portalCategory = [
                'post_id'   => $id,
                'category_id' => 1,
                'list_order' => 10000,
                'status' => 1,
            ];
            Db::name('portal_category_post')->insert($portalCategory);
            Db::name('gather_url')->where('id',$url['id'])->setField('isdel', 3);
        //}
    }
    //模拟请求
    function https_post($url, $type = "GET", $data = '')
    {
        $ch = curl_init();
        curl_setopt($ch,CURLOPT_URL,$url);
        curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
        curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,0);
        curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,0);
        curl_setopt($ch,CURLOPT_HEADER,0);
    
        $type = strtolower($type);
        switch ($type){
            case 'get':
                break;
            case 'post':
                //post请求配置
                curl_setopt($ch, CURLOPT_POST,1);
                curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
                break;
        }
        $result = curl_exec($ch);
        curl_close($ch);
        return $result;
    }
public function async(){
//PHP 中如何 在客户端触发，然后在服务器端执行一个函数，页面关闭也继续执行。要先返回用户请求不要等待时。

 ob_end_clean();#清除之前的缓冲内容，这是必需的，如果之前的缓存不为空的话，里面可能有http头或者其它内容，导致后面的内容不能及时的输出
 header("Connection: close");//告诉浏览器，连接关闭了，这样浏览器就不用等待服务器的响应
 header("HTTP/1.1 200 OK"); //可以发送200状态码，以这些请求是成功的，要不然可能浏览器会重试，特别是有代理的情况下
 //return false;//加了这个下面的就不执行了，不加这个无法返回页面状态，浏览器一直在等待状态，可以关闭，但不是要的效果。
 //die(); 或 return ;也一样不执行下面的
 //rundata();
 //register_shutdown_function("rundata");
 //return  ;
 ob_start();#开始当前代码缓冲
header("Content-type:text/html;charset=utf-8");

 //下面输出http的一些头信息
 $size=ob_get_length();
 header("Content-Length: $size");
 ob_end_flush();#输出当前缓冲
 flush();#输出PHP缓冲

 #休眠PHP，也就是当前PHP代码的执行停止，1秒钟后PHP被唤醒，
 #PHP唤醒后，继续执行下面的代码，但这个时候上面代码的结果已经输出浏览器了，
 #也就是浏览器从HTTP头中知道了服务端关闭了连接，浏览器将不在等待服务器的响应，
 #反应给客户的就是页面不会显示处于加载状态中，换句话说用户可以关掉当前页面，或者关掉浏览器，
 #PHP唤醒后继续执行下面的代码，这也就实现了PHP后台执行的效果，
 #休眠的作用只是让php先把前面的输出作完，不要急于马上执行下面的代码，休息一下而已，也就是说下面的代码
 #执行的时候前面的输出应该到达浏览器了
 sleep(1);
 echo '这里的输出用户看不到，后台运行的';

 //下面代码的任何输出都不会输出给浏览器，因为http连接已经关了，
 //所以下面的代码的执行属于后台运行的

 ignore_user_abort(true); // 后台运行，这个只是运行浏览器关闭，并不是直接就中止返回200状态。
 set_time_limit(0); // 取消脚本运行时间的超时上限
 rundata();
$i=0;
     do{
         sleep(60); // 休眠1分钟
         $i++;
         error_log($i.'-',3,'aa.txt');
     }while(true);

function rundata(){//do something
}
}

//分配金卡积分
public function addPoints(){
    $orderModel = new \app\common\model\Order();
    $deposit['tradeId']       = 70;
    $deposit['phone']         = '18680834376';
    $deposit['consumeAmount'] = 1500.00;
    $deposit['consumeType']   = 'day_consume';
    $addUserPointsResult =$orderModel ->consumeToAddUserPoints($deposit);
    var_dump($addUserPointsResult['Msg']);
}
}

